package com.fyzk.activity.lottery.togetherbuy;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;

import com.tyjc.lottery.R;


public class ZhanJiView {
	
	private static final int dan = 1;
	private static final int BAN_XING = dan / 2;	//半颗星
	private static final int XING1 = dan;			//星
	private static final int XING2 = 4 * XING1;		//月亮
	private static final int XING3 = 4 * XING2;		//太阳
	private static final int XING4 = 4 * XING3;		//钻
	private static final int XING5 = 4 * XING4;		//皇冠

	public static View getZhanJiView(Context context, String zhanJi){
//		zhanJi = "1653";
		View view = LayoutInflater.from(context).inflate(R.layout.zhanjiview, null);
		LinearLayout ll = (LinearLayout) view.findViewById(R.id.zhanji_ll);
		
		int zhJ = 0;
		try {
			zhJ = Integer.parseInt(zhanJi);
		} catch (Exception e) {
			// TODO: handle exception
			return view;
		}
		
		for (int i = 0; i < getXing5_Num(zhJ); i++) {
			ll.addView(getXing5Img(context));
		}
		zhJ = zhJ - getXing5_Num(zhJ) * XING5;
		
		for (int i = 0; i < getXing4_Num(zhJ); i++) {
			ll.addView(getXing4Img(context));
		}
		zhJ = zhJ - getXing4_Num(zhJ) * XING4;
		
		for (int i = 0; i < getXing3_Num(zhJ); i++) {
			ll.addView(getXing3Img(context));
		}
		zhJ = zhJ - getXing3_Num(zhJ) * XING3;
		
		for (int i = 0; i < getXing2_Num(zhJ); i++) {
			ll.addView(getXing2Img(context));
		}
		zhJ = zhJ - getXing2_Num(zhJ) * XING2;
		
		for (int i = 0; i < getXing1_Num(zhJ); i++) {
			ll.addView(getXing1Img(context));
		}
		zhJ = zhJ - getXing1_Num(zhJ) * XING1;
		
//		for (int i = 0; i < getXing_ban_Num(zhJ); i++) {
//			ll.addView(getXingBanImg(context));
//		}
		
		
		return view;
	}
	
	private static int getXing5_Num(int zhanJi){
		return zhanJi / XING5;
	}
	
	private static int getXing4_Num(int zhanJi){
		return zhanJi / XING4;
	}
	
	private static int getXing3_Num(int zhanJi){
		return zhanJi / XING3;
	}
	
	private static int getXing2_Num(int zhanJi){
		return zhanJi / XING2;
	}
	
	private static int getXing1_Num(int zhanJi){
		return zhanJi / XING1;
	}
	
	private static int getXing_ban_Num(int zhanJi){
		if (zhanJi % XING1 < BAN_XING) {
			return 0;
		}else{
			return 1;
		}
	}
	
	private static ImageView getXing5Img(Context context){
		ImageView img = new ImageView(context);
		img.setImageResource(R.drawable.zhanji_xing5);
		img.setScaleType(ScaleType.FIT_CENTER);
		return img;
	}
	
	private static ImageView getXing4Img(Context context){
		ImageView img = new ImageView(context);
		img.setImageResource(R.drawable.zhanji_xing4);
		img.setScaleType(ScaleType.FIT_CENTER);
		return img;
	}
	
	private static ImageView getXing3Img(Context context){
		ImageView img = new ImageView(context);
		img.setImageResource(R.drawable.zhanji_xing3);
		img.setScaleType(ScaleType.FIT_CENTER);
		return img;
	}
	
	private static ImageView getXing2Img(Context context){
		ImageView img = new ImageView(context);
		img.setImageResource(R.drawable.zhanji_xing2);
		img.setScaleType(ScaleType.FIT_CENTER);
		return img;
	}
	
	private static ImageView getXing1Img(Context context){
		ImageView img = new ImageView(context);
		img.setImageResource(R.drawable.zhanji_xing);
		img.setScaleType(ScaleType.FIT_CENTER);
		return img;
	}
	
	private static ImageView getXingBanImg(Context context){
		ImageView img = new ImageView(context);
		img.setImageResource(R.drawable.zhanji_xing_no);
		img.setScaleType(ScaleType.FIT_CENTER);
		return img;
	}
	
}
